import request from '@/utils/request'
const UpmsUserOrganizationService = {
  state: {},

  mutations: {},

  actions: {
    // 用户分页
    upmsUserPageByOrgId({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.get('userOrganization/pageByOrgId', params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 获取用户详情
    getUserByUserOrgId({ commit }, userOrgId) {
      return new Promise((resolve, reject) => {
        request.get('userOrganization/getDetailsById/' + userOrgId, { }).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 添加用户
    organizationUserSave({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post('userOrganization/save', {
          'userId': params.userId,
          'fullOrganizationId': params.fullOrganizationId,
          'organizationId': params.organizationId,
          'job': params.job,
          'orders': params.orders,
          'phone': params.phone,
          'type': params.type
        }).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 修改用户
    organizationUserUpdate({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post('userOrganization/update/' + params.id, {
          'userId': params.userId,
          'fullOrganizationId': params.fullOrganizationId,
          'organizationId': params.organizationId,
          'job': params.job,
          'orders': params.orders,
          'phone': params.phone,
          'type': params.type
        }).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 移除用户
    organizationUserRemove({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post('userOrganization/remove', params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 校验用户是否在组织下添加
    validateOrganizationUserExist({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.get('userOrganization/validateExist', params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default UpmsUserOrganizationService
